#include<bits/stdc++.h>
using namespace std;
const int N = 10010;
int n, m, k;
int dist[N], backup[N];
struct edge{
    int a, b, w;
}edge[N];
int bellman_ford(){
    memset(dist, 0x3f, sizeof dist);
    dist[1] = 0;
    for(int i = 1; i <= k; i ++ ){
        memcpy(backup, dist, sizeof dist);
        for(int j = 1; j <= m; j ++ ){
            int a = edge[j].a, b = edge[j].b, w = edge[j].w;
            dist[b] = min(dist[b], backup[a] + w);
        }
    }
    return  dist[n];
}
int main(){
    cin >> n >> m >> k;
    for(int i = 1; i <= m; i ++ ){
        int x, y, z;
        cin >> x >> y >> z;
        edge[i].a = x;
        edge[i].b = y;
        edge[i].w = z;
    }
    int t = bellman_ford();
    if(t >= 0x3f3f3f3f / 2)
        puts("impossible");
    else
        cout << t << endl;
    return 0;
}